/**
 * Created by zhuyun on 3/30/16.
 */
module.exports = function (grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        uglify: {
            options: {
                banner: '/* <%=pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
            },
            build: {
                src: 'src/<%= pkg.name %>.js',
                dest: 'build/<%= pkg.name %>.min.js'
            }
        },
        mytest: {
            foo: [1,2,3],
            bar: 'hello world',
            baz: false,
            cut: 'cut'
        }
    });

    grunt.registerMultiTask('mytest','log stuff',function(){ //多任务
        grunt.log.writeln(this.target+':'+this.data)
    })

    grunt.registerTask('foo', 'a sample task', function(arg1, arg2){
        if(arguments.length ===0){
            grunt.log.writeln(this.name + ", no args");  //this.name refer to task name
        }else{
            grunt.log.writeln(this.name+','+arg1+' '+arg2);
        }
    })

    grunt.registerTask('zb', 'this is zb', function(){//单任务
        grunt.log.writeln('currently running the zb task')
        grunt.task.run('foo', 'mytest')
    })


    grunt.registerTask('asyncfoo', 'asyncfoo task', function(){ // async
        var done= this.async();
        grunt.log.writeln('processing task');
        setTimeout(function(){
            grunt.log.writeln('all done')
            done();
        },10000)
    })

    grunt.loadNpmTasks('grunt-contrib-uglify');


    grunt.registerTask('default', ['uglify']);

    grunt.registerTask('foo1', 'my foo task', function(){
        return false;
    })
    grunt.registerTask('bar1', 'my bar task', function(){
        grunt.task.requires('foo1')

        grunt.log.writeln('hello world')
    })











}
